import ManagerMap from './ManagerMap'

export default class CommonUtils {

  private static instance: CommonUtils;


  /**
   * 非formsheet模式
   */
  private NO_FORM_SHEET_STATUS: number = 0;

  /**
   * 复位统计formsheet的状态
   */
  private REST_FORM_SHEET_STATUS: number = 1;

  /**
   * 开始统计push状态
   */
  private START_PUSH_FORM_SHEET_STATUS: number = 2;


  /**
   * 统计formsheet执行完毕后最大计数，用于判断打开到关闭状态
   */
  private MAX_FORM_SHEET_STATUS: number = 5;



  private constructor() {
  }

  public static getInstance(): CommonUtils {
    if (!CommonUtils.instance) {
      CommonUtils.instance = new CommonUtils();
    }
    return CommonUtils.instance;
  }

  public handleFormSheetAnimation(tag: number, isFormSheetModel: boolean): boolean {
    let formSheetCount = ManagerMap.getInstance().formSheetCountMap.get(tag);
    console.log("====handleFormSheetAnimation====tag "+tag+" === "+isFormSheetModel +" formSheetCount "+formSheetCount)
    if ((formSheetCount && (formSheetCount > this.MAX_FORM_SHEET_STATUS))) {
      ManagerMap.getInstance().formSheetCountMap.set(tag, this.NO_FORM_SHEET_STATUS);
      return false
    }
    if (!isFormSheetModel && (formSheetCount && formSheetCount >= this.START_PUSH_FORM_SHEET_STATUS && formSheetCount < this.MAX_FORM_SHEET_STATUS)) {
      formSheetCount = formSheetCount + 1;
      ManagerMap.getInstance().formSheetCountMap.set(tag, formSheetCount);
      return false;
    }

    if (isFormSheetModel && ((formSheetCount && (formSheetCount == this.REST_FORM_SHEET_STATUS || formSheetCount == this.MAX_FORM_SHEET_STATUS)))) {
       formSheetCount = formSheetCount + 1;
       ManagerMap.getInstance().formSheetCountMap.set(tag, formSheetCount);
       return false;
    }
    if (isFormSheetModel && ((formSheetCount && formSheetCount <= this.NO_FORM_SHEET_STATUS && formSheetCount < this.MAX_FORM_SHEET_STATUS) || !formSheetCount)) {
      console.log("====handleFormSheetAnimationgogo====tag "+tag+" === "+isFormSheetModel +" formSheetCount "+formSheetCount)
      ManagerMap.getInstance().formSheetCountMap.set(tag, this.REST_FORM_SHEET_STATUS);
      return false;
    }
    return true;
  }
}